/**
 * AT25F1024A(1Mbit) 容量: 128KB=0x20000
 * Address范围(0x00)~(0x1FFFF)
 * 扇区地址:(000000~007FFF)
 * 扇区地址:(008000~00FFFF)
 * 扇区地址:(010000~017FFF)
 * 扇区地址:(018000~01FFFF)
 *      SPI-Flash
 * CS-芯片选择 SCK-时钟 SI-数据输入 SO-数据输出  WP-写保护   HOLD-暂停串行输入
 */

#ifndef __AT25F1024_H
#define __AT25F1024_H
#include "SimulateSPI.h"

#define AT25F1024_CMD_WRITE_ENABLE 0x06    // 写芯片使能(在指令或数据前先要使能)
#define AT25F1024_CMD_WRITE_DISABLE 0x04   // 禁止写芯片
#define AT25F1024_CMD_READ_STATUS_REG 0x05 // 读状态寄存器
#define AT25F1024_CMD_READ_DATA 0x03       // 读取存储器数据
#define AT25F1024_CMD_WRITE_DATA 0x02      // 页编程
#define AT25F1024_CMD_ERASE_SECTOR 0x52    // 扇区擦除
#define AT25F1024_CMD_CHIP_ERASE 0x62      // 全片擦除
#define AT25F1024_CMD_READ_ID 0x15         // 读取芯片ID

void AT25F1024_Init(void);
void AT25F1024_WriteEnable(void);
void AT25F1024_WaitBusy(void);
void AT25F1024_ReadBuffer(uint32_t addr, uint8_t *pBuffer, uint16_t len);
void AT25F1024_WriteBuffer(uint32_t addr, uint8_t *pBuffer, uint16_t len);
void AT25F1024_EraseSector(uint32_t addr);
uint16_t AT25F1024_GetID(void);
#endif
